import axios from 'axios'
axios.defaults.baseURL = 'https://lianghj.top:8888/api/private/v1/'
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
export default function ajax (url = '', params = {}, type = 'get') {
  return new Promise((resolve, reject) => {
    let promise
    if (type.toUpperCase === 'GET') {
      promise = axios({
        url,
        params
      })
    } else if (type.toUpperCase === 'POST') {
      promise = axios({
        method: 'POST',
        url,
        data: params
      })
    }
    promise.then((res) => { resolve(res) }).catch()
  })
}
